<meta charset="UTF-8">
<style>
    dl{
        float: left;
        text-align: center;
        margin: 20px;
    }
</style>
<input type="text" placeholder="Promise 封装Get">
<ul></ul>

<br>
<hr>
<br>

<button>获取最新电影Promise 封装GET</button>
<ol></ol>

<script src="./Promise get post封装.js"></script>
<script>
    // get封装调用百度搜索
document.querySelector('input').oninput=function(){
    clearTimeout(t)
    t=setTimeout(()=>{
    get( `http://www.baidu.com/sugrec`,
               {prod:'pc',wd:document.querySelector('input').value},
               'json'
       ).then( res=>{   
                if(res && res.g){
                       document.querySelector('ul').innerText=''
                   res.g.forEach(item=>{
                       let liObj=document.createElement('li')
                       liObj.innerText=item.q
                       document.querySelector('ul').appendChild(liObj)
                       })
                } else {
                   document.querySelector('ul').innerHTML=`<li>未搜索到相关数据</li>`
                }},
               err=>{    console.log(err)    }
            )
    },1500)
}

//卖座网电影   url,params,type,headers
document.querySelector('button').onclick=function(){
    get('https://m.maizuo.com/gateway',                                                                        //url
        {cityId:320100,pageNum:1,pageSize:10,type:1,k:8920637},                                                //params
        'json',                                                                                                //type
        {'X-Client-Info':'{"a":"3000","ch":"1002","v":"5.2.0","e":"1651754242929143160045569","bc":"320100"}', //headers
         'X-Host':'mall.film-ticket.film.list',
         'X-Requested-With':'XMLHttpRequest',
         'X-Token':'undefined'}
    ).then(
        res=>{
            let olObj=document.querySelector('ol')
            olObj.innerHTML=''
            if(!Array.isArray(res.data.films)) return    //多家一步过滤，防止后端数据出现误差
            res.data.films.forEach(item=>{
                let liObj=document.createElement('dl')
                liObj.innerHTML=`<dt><img src='${item.poster}' width='200' height='300'/></dt>
                <dt>${item.name}</dt> `
                olObj.appendChild(liObj)
            })
        },
        err=>{    console.log(err)    }
    )
}
</script>